<template>
	<view>
		<view class="imgContainer">
			<image :src="fieldData.url" mode="aspectFill" ></image>
		</view>
		<uni-card :title="fieldData.name" extra="导航">
			<text class="uni-body">
				名称：{{fieldData.name}}\n
				校区：{{fieldData.department}}\n
				营业时间：\n
				场馆地址：\n
			</text>

		</uni-card>
		<button class="button" type="primary" @click="onClick">
			导航
		</button>
	</view>
</template>

<script>
	export default{
    onLoad(query) {
      // console.log(query); // 确保输出接收到的 query 对象
      if (query && query.fieldData) {
        try {
          this.fieldData = JSON.parse(decodeURIComponent(query.fieldData));
          // console.log(this.fieldData); // 确认解析后的数据
        } catch (error) {
          console.error('Failed to parse fieldData:', error);
        }
      } else {
        console.warn('No fieldData found in query:', query);
      }
    },
		data(){
			return{
				fieldData:{},
				la:'',
				lo:'',
			};
		},
		methods:{
			onClick(){
				console.log(1);
				console.log(this.fieldData.latitude);
				console.log(this.fieldData.longitude)
						uni.getLocation({
						  type: 'gcj02', //返回可以用于uni.openLocation的经纬度
						  success: (res) =>{
						    uni.openLocation({
								latitude: this.fieldData.latitude,
								longitude: this.fieldData.longitude,
								// latitude:1,
								// longitude:1,
						      success:()=> {
						        console.log('success');
						      }
						    });
						  }
						});
			}
		}
	};
</script>
<!-- // <script setup> 
// import { ref, onMounted } from 'vue';
// import { useRouter } from 'vue-router';

// const router = useRouter();
// const fieldData = ref([]);

// onMounted(() => {
//   const queryFieldData = router.currentRoute.value.query.fieldData;
//   if (queryFieldData) {
//     fieldData.value = JSON.parse(decodeURIComponent(queryFieldData));
//   }
//   console.log(fieldData.value);
// });
// 	function onClick(){
// 		uni.getLocation({
// 		  type: 'gcj02', //返回可以用于uni.openLocation的经纬度
// 		  success: function (res) {
// 		    uni.openLocation({
// 				latitude:fieldData.value.latitude,
// 				longitude:fieldData.value.longitude,
				
// 		      latitude: 30.527658980298032,
// 		      longitude: 114.36133040050717,
// 		      success: function () {
// 		        console.log('success');
// 		      }
// 		    });
// 		  }
// 		});
// 	}
// </script> -->

<style lang="scss" scoped>
.imgContainer{
	width: 750rpx;
	height: 400rpx;
	padding: 0 20rpx;
	image{
		width: 100%;
		height: 100%;
		border-radius: 15rpx;
	}
}
	.button {
		width: 40%;
		display: flex;
		justify-content: center;
		align-items: center;
		border-radius: 20rpx; /* 添加圆角效果 */
	}
</style>
